/*
 * atmega16_sd.c
 *
 * Created: 2011.10.18 20:14:40
 *  Author: Administrator
 */ 

#include <avr/io.h>
#include <util/delay.h>

#include "driver/sdc.h"
#include "driver/tda1543.h"

void LED_init()
{
	DDRB|=1<<PB0;
	//PORTB|=1<<PB0;
}

void LED_off()
{
	PORTB|=1<<PB0;
}

void LED_on()
{
	PORTB&=~(1<<PB0);
}

void busy()
{
	while(1)
	{
		LED_on();
		_delay_ms(100);
		LED_off();
		_delay_ms(100);
	}
}

void normal()
{
	LED_on();
	_delay_ms(1000);
	LED_off();
	_delay_ms(1000);
}

void USART_txd(unsigned char data)
{
	while ( !( UCSRA & (1<<UDRE)) );
	UDR = data;
}

void USART_init()
{
	UBRRL=51;
	UCSRB=(1<<RXCIE) | (1<<RXEN) | (1<<TXEN);
	UCSRC=(1<<URSEL) | (1<<UCSZ1) | (1<<UCSZ0);
	
	USART_txd('\n');
	
	USART_txd(0xaa);
	USART_txd(0x55);
	USART_txd(0x55);
	USART_txd(0xaa);
}



int main(void)
{
	unsigned short i;
	unsigned char block[512];
	
	USART_init();
	
	LED_init();
	
	SDC_init();		
	
	_delay_ms(100);
	
	SDC_readblock(0,block,0);
	for (i=0;i<512;i++)
	{
		USART_txd(block[i]);
	}
	
	TDA1543_init();
	
    while(1)
	{
		TDA1543_output(0,0xffff);
	}
	
	while(1);
}